package gui.arp;

import javax.swing.table.AbstractTableModel;

import data.ArpTemplate;

@SuppressWarnings("serial")
public class ArpTableModel extends AbstractTableModel {
	private ArpTemplate template;
	
	public ArpTableModel(ArpTemplate template) {
		super();
		this.template = template;
	}

	@Override
	public int getColumnCount() {
		return 17;
	}

	@Override
	public int getRowCount() {
		return 3;
	}

	@Override
	public Object getValueAt(int row, int column) {
		if (row == 0) {
			if (column != 0) return "" + column;	
		}
		else if (column == 0) {
			switch (row) {
			case 1:
				return "TUNE";
			case 2:
				//return "TUNE";
			}
		}
		else if (row == 1) {
			//System.out.println(getTableModelListeners().length);
			//System.out.println("Steps: " + template.getSteps());
			if (column < template.getSteps() + 1) {
				return "" + template.getTune()[column - 1];
			}
		}
		return "";
	}
	
	@Override
	public void	setValueAt(Object aValue, int rowIndex, int columnIndex) {
		if (rowIndex == 1 && columnIndex > 0) {
			template.getTune()[columnIndex - 1] = Integer.parseInt((String) aValue);
			fireTableCellUpdated(rowIndex, columnIndex);
		}
	}
	
	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		if (rowIndex > 0 && columnIndex > 0 && columnIndex - 1 < template.getSteps()) return true;
		return false;
	}
	
	public void updateTable() {
		fireTableDataChanged();
	}
	
	public void setTemplate (ArpTemplate template) {
		this.template = template;
	}
}
